package com.syaccp.utils;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import com.syaccp.exception.CrmebException;
import com.syaccp.model.SysUser;

import cn.hutool.core.util.ObjectUtil;

public class SecurityUtil {
	
	 /**
     * 获取管理员信息（从security中）
     */
    public static SysUser getLoginUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        SysUser sysUser = (SysUser) authentication.getPrincipal();
        if (ObjectUtil.isNull(sysUser)) {
            throw new CrmebException("登录信息已过期，请重新登录");
        }
        return sysUser;
    }


}
